package com.example.product.dubbo;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyFactory {

    public static <T> T getProxy(final Class<T> interfaceClass) {
        return (T) Proxy.newProxyInstance(interfaceClass.getClassLoader(),
                new Class[]{interfaceClass}, (Object proxy, Method method, Object[] args) -> {
                    System.out.println("proxy:" + proxy.getClass() + ",method:" + method.getName() + ",args:" + args);
                    HttpClient httpClient = new HttpClient();
                    Invocation invocation = new Invocation(interfaceClass.getName(), method.getName(),
                            method.getParameterTypes(), args);
                    return httpClient.send("localhost", 8008, invocation);
                });
    }
}
